package com.rw.bootdemo.quartz;

import com.rw.bootdemo.cache.RedisCache;
import com.rw.bootdemo.service.UserService;
import com.sun.xml.internal.ws.api.policy.SourceModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author rabit
 */
@Configuration
public class TestQuartz {
    Logger logger = LoggerFactory.getLogger(TestQuartz.class);
    @Autowired
    private UserService userService;

    @Autowired
    private RedisCache redisCache;

    @Scheduled(cron = "0/5 * * * * *")
    public void testQuartz1(){
        System.out.println("TestQuartz.testQuartz1-执行了");
        Boolean flag = Boolean.parseBoolean(redisCache.get("quartz_flag").toString());
        if (flag){
            logger.error("--------定时器执行了-------"+userService.getAllUsers());
        }else {
            logger.error("--------定时器中判断条件不成立-------");
        }
    }
}
